/******************************************************************************
 * (C) 成都齐乐科技有限公司
 * 描述：加载任务。
 *****************************************************************************/

function LoadTask(finishCb) {
    this._finishCb = finishCb;
    this._tasks = {};
    this._totalTaskNum = 0;
    this._finishedTaskNum = 0;

    this.addLoad = function (name) {
        if (!this._tasks.hasOwnProperty(name)) {
            this._tasks[name] = 1;
            this._totalTaskNum += 1;
            return;
        }

        throw new Error("HAVE SAME TASK");
    };

    this.finishLoad = function(name) {
        if (this._tasks.hasOwnProperty(name)) {
            delete this._tasks[name];
            this._finishedTaskNum += 1;

            if (this._finishedTaskNum == this._totalTaskNum) {
                this._finishCb && this._finishCb();
            }
            return;
        }

        throw new Error("NOT ADD THIS TASK");
    };
}

exports.LoadTask = LoadTask;